Please visit https://github.com/Shekharrajak/daru-data_tables for updated API and examples. It works in Ruby web application framework but there is already an issue open for IRuby notebook: https://github.com/Shekharrajak/daru-data_tables/issues/2
In [1]:
require 'daru/data_tables'
require 'daru'
Out[1]:
In [2]:
df = Daru::DataFrame.new({b: [11,12,13,14,15], a: [1,2,3,4,5],
c: [11,22,33,44,55]},
order: [:a, :b, :c],
index: [:one, :two, :three, :four, :five])
Out[2]:
In [3]:
# Please refer: https://github.com/Shekharrajak/daru-data_tables/issues/2
# Daru::View::DataTables.init_iruby
# t = DataTables::DataTable.new(pageLength: 3)
# t.to_html
# t.to_html(id='table_id1')
# table_opts = {
# class: "display",
# cellspacing: "0",
# width: "100%"
# }
# options ={
# table_options: table_opts
# }
# t.to_html(id='table_id1', options)
# id is automatically added into table_options
# options
# options[:table_options][:table_html] = df.to_html_thead + df.to_html_tbody
# html_code = t.to_html(id='table_id1', options)
# Fix me: It is showing normal html code. That means DataTables js and css is not working or loading.
# IRuby.html html_code
# html_code.html_safe
# Fix me: It is showing normal html code. That means DataTables js and css is not working or loading.
# IRuby.html html_code
# t_opts = {
# data: [[1,1,1],
# [1,2,3],
# [11,12,13],
# [1,2,3],
# [11,12,13],
# [1,2,3],
# [11,12,13]
# ],
# pageLength: 4
# }
# table_from_array = DataTables::DataTable.new(t_opts)
# table_opts = {
# class: "display",
# cellspacing: "0",
# width: "50%",
# table_html: "
# <thead>
# <tr>
# <th>Num1 </th>
# <th>Num2 </th>
# <th>Num3 </th>
# </tr>
# </thead>"
# }
# options = {
# table_options: table_opts
# }
# html_code_array_sorted = table_from_array.to_html(id='table_id4', options)
# IRuby.html html_code_array_sorted
# IRuby.display(IRuby.javascript(table_from_array.to_html('id1')))
# IRuby.html(table_from_array.to_html(id='table_id4', options))
# table_html = "
# <table id='id1'>
# <thead>
# <tr>
# <th>Num1 </th>
# <th>Num2 </th>
# <th>Num3 </th>
# </tr>
# </thead>
# </table>"
# IRuby.html table_html
In [ ]: